﻿using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using SheepStorage.API.Application.Command.ProviderManageCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Dto.InputDto;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.ProviderManageHandler
{
    public class ProviderManageSelectHandler:IRequestHandler<ProviderManageSelectCommand,Results<PageOutput<ProviderManage>>>
    {
        private readonly IProviderManageService _providerService;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="providerService"></param>
        /// <param name="mapper"></param>
        public ProviderManageSelectHandler(IProviderManageService providerService,IMapper mapper)
        {
            _providerService = providerService;
            _mapper = mapper;
        }

        /// <summary>
        /// 供应商列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<PageOutput<ProviderManage>>> Handle(ProviderManageSelectCommand request, CancellationToken cancellationToken)
        {
            var manlist = _mapper.Map<PageInput>(request);

            var list = _mapper.Map<PageOutput<ProviderManage>>(await _providerService.GetProviderManage(manlist));

            return Results<PageOutput<ProviderManage>>.DataResult(list);
        }


    }
}
